<template>
	<baseDialog ref="dialogRef" :title="dialogTitle" width="680px" :showFooter="false" @close="handleClose">
		<el-descriptions class="w-full" direction="horizontal" :column="1" border>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="发送消息标识">
				{{ detailData.msg_token }}
			</el-descriptions-item>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="通知账号">
				{{ detailData.account }}
			</el-descriptions-item>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="通知标题">
				{{ detailData.title }}
			</el-descriptions-item>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="通知内容">
				{{ detailData.content }}
			</el-descriptions-item>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="通知端口">
				{{ detailData.notice_type_desc }}
			</el-descriptions-item>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="消息类型">
				{{ detailData.is_captcha ? '验证码' : '消息通知' }}
			</el-descriptions-item>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="发送类型">
				{{ detailData.send_type_desc }}
			</el-descriptions-item>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="状态">
				{{ detailData.status_desc }}
			</el-descriptions-item>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="错误信息">
				{{ detailData.error }}
			</el-descriptions-item>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="读取状态">
				{{ detailData.read_desc }}
			</el-descriptions-item>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="读取时间">
				{{ detailData.read_time_desc }}
			</el-descriptions-item>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="发送时间">
				{{ detailData.send_time_desc }}
			</el-descriptions-item>
			<el-descriptions-item class-name="el-descriptions-content-break" label-class-name="w-[130px]" label="创建时间">
				{{ detailData.create_time }}
			</el-descriptions-item>
		</el-descriptions>
	</baseDialog>
</template>

<script setup lang="ts" name="messageLogDetail">
import { ref, reactive, computed } from 'vue';
import { noticeLogDetail } from '/@/api/setting/notice';

const dialogRef = ref(null);

const dialogTitle = computed(() => {
	return '发送记录详情';
});

const emit = defineEmits(['close']);

const detailData = reactive({
	id: 0,
	msg_token: '',
	account: '',
	title: '',
	content: '',
	notice_type_desc: '',
	send_type_desc: '',
	status_desc: '',
	read_desc: '',
	is_captcha: '',
	read_time_desc: '',
	send_time_desc: '',
	create_time: '',
	error: '',
	status: 1,
});

const setFormData = async (row: any, callback: any) => {
	const data = await noticeLogDetail({
		id: row.id,
	});

	for (const key in detailData) {
		if (data[key] != null && data[key] != undefined) {
			detailData[key] = data[key];
		}
	}

	callback();
};

const handleClose = () => {
	emit('close');
};

const open = () => {
	dialogRef.value?.open();
};

defineExpose({
	open,
	setFormData,
});
</script>
